<?php
class GpsesController extends AppController {

	var $name = 'Gpses';
	var $helpers = array('Html', 'Form');
	var $paginate = array('limit' =>10, 'page' => 1);
	function index() {
		$this->Gpse->recursive = 0;
		$this->set('gpses', $this->paginate());
	}

	function view($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid Gpse.', true));
			$this->redirect(array('action'=>'index'));
		}
		$this->set('gpse', $this->Gpse->read(null, $id));
	}

	function add() {
		if (!empty($this->data)) {
			$this->Gpse->create();
			if ($this->Gpse->save($this->data)) {
				$this->Session->setFlash(__('GPS đã lưu', true));
				$this->redirect(array('action'=>'index'));
			} else {
				$this->Session->setFlash(__('Không thể lưu. Thử lại lần nữa.', true));
			}
		}
		$sotays = $this->Gpse->Sotay->find('list');
		$this->set(compact('sotays'));
	}

	function edit($id = null) {
		if (!$id && empty($this->data)) {
			$this->Session->setFlash(__('Invalid Gpse', true));
			$this->redirect(array('action'=>'index'));
		}
		if (!empty($this->data)) {
			if ($this->Gpse->save($this->data)) {
				$this->Session->setFlash(__('GPS đã lưu', true));
				$this->redirect(array('action'=>'index'));
			} else {
				$this->Session->setFlash(__('Không thể lưu. Thử lại lần nữa.', true));
			}
		}
		if (empty($this->data)) {
			$this->data = $this->Gpse->read(null, $id);
		}
		$sotays = $this->Gpse->Sotay->find('list');
		$this->set(compact('sotays'));
	}

	function delete($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid id for Gpse', true));
			$this->redirect(array('action'=>'index'));
		}
		if ($this->Gpse->del($id)) {
			$this->Session->setFlash(__('GPS đã xóa', true));
			$this->redirect(array('action'=>'index'));
		}
	}

}
?>